package com.example.administrator.myapplication.fragment;


import android.databinding.DataBindingUtil;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import com.example.administrator.myapplication.R;
import com.example.administrator.myapplication.databinding.FragmentSubscribeBinding;
import com.example.administrator.myapplication.subscribe.SubCommentFragment;
import com.example.administrator.myapplication.subscribe.SubHistoryFragment;
import com.example.administrator.myapplication.subscribe.SubSubFragment;
import com.example.administrator.myapplication.until.CommentFragmentPagerAdapter;

import java.util.ArrayList;
import java.util.List;

/**
 * A simple {@link Fragment} subclass.
 */
public class SubscribeFragment extends Fragment {
    private FragmentSubscribeBinding binding;
    private CommentFragmentPagerAdapter adapter;

    public SubscribeFragment() {
        // Required empty public constructor
    }


    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        return DataBindingUtil.inflate(inflater,R.layout.fragment_subscribe, container, false).getRoot();
    }

    @Override
    public void onViewCreated(View view, @Nullable Bundle savedInstanceState) {
        super.onViewCreated(view, savedInstanceState);
        binding = DataBindingUtil.getBinding(view);
        aboutTablayout();
    }

    private void aboutTablayout() {
        String title[]  = new String[]{"推荐","订阅","历史"};
        List<Fragment>  fragments = new ArrayList<>();
        fragments.add(new SubSubFragment());
        fragments.add(new SubCommentFragment());
        fragments.add(new SubHistoryFragment());
        adapter = new CommentFragmentPagerAdapter(getChildFragmentManager(),title,fragments);
        binding.viewpager.setAdapter(adapter);
        binding.tablayout.setupWithViewPager(binding.viewpager);
    }
}
